{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}
{{#if view.showActions}}
<div class="dataset-details">
  <div class="top-left">
    <h4>{{view.dataset.name}}</h4>
  </div>
  <div class="bottom-left">
    <table>
      <tr>
        <td>{{t mirroring.dataset.source}}:</td>
        <td>{{view.dataset.sourceClusterName}}</td>
        <td>{{view.dataset.sourceDir}}</td>
      </tr>
      <tr>
        <td>{{t mirroring.dataset.target}}:</td>
        <td>{{view.dataset.targetClusterName}}</td>
        <td>{{view.dataset.targetDir}}</td>
      </tr>
    </table>
  </div>
  {{#if App.isAdmin}}
    <div class="top-right">
      <div class="btn-group pull-right">
        <button class="btn">{{t common.actions}}</button>
        <button class="btn dropdown-toggle" data-toggle="dropdown">
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu pull-right">
          {{#if view.dataset.isSuspended}}
            <li>
              <a href="javascript:void(null);" {{action resume target="controller"}}>
                {{t mirroring.dataset.resume}}
              </a>
            </li>
          {{/if}}
          {{#if view.dataset.isRunning}}
            <li>
              <a href="javascript:void(null);" {{action suspend target="controller"}}>
                {{t mirroring.dataset.suspend}}
              </a>
            </li>
          {{/if}}
          {{#if view.dataset.isSubmitted}}
            <li>
              <a href="javascript:void(null);" {{action schedule target="controller"}}>
                {{t mirroring.dataset.schedule}}
              </a>
            </li>
          {{/if}}
          <li>
            <a {{action editDataset}} href="javascript:void(null);">
              {{t common.edit}}
            </a>
          </li>
          <li>
            <a href="javascript:void(null);" {{action delete target="controller"}}>
              {{t common.delete}}
            </a>
          </li>
        </ul>
      </div>
      <span {{bindAttr class=":label view.dataset.isRunning:label-info  view.dataset.isSuspended:label-warning  view.dataset.isSubmitted:label-success :pull-right :dataset-status"}}>
        {{view.dataset.statusFormatted}}</span>
    </div>
  {{/if}}
  <div class="bottom-right">{{t common.download}}: <a href="javascript:void(null);" {{action downloadEntity target="controller"}}>{{t mirroring.dataset.entity}}.xml</a></div>
</div>
{{/if}}
<div class="dataset-instances">
  <table class="table table-bordered table-striped">
    <thead>
      {{#view view.sortView contentBinding="view.filteredContent" class="label-row"}}
        <th class="first"></th>
        {{view view.parentView.idSort}}
        {{view view.parentView.startSort}}
        {{view view.parentView.endSort}}
        {{view view.parentView.statusSort}}
      {{/view}}
    <tr class="filter-row">
      <th class="first"></th>
      <th>{{view view.idFilterView}}</th>
      <th>{{view view.startFilterView}}</th>
      <th>{{view view.endFilterView}}</th>
      <th>{{view view.statusFilterView}}</th>
    </tr>
    </thead>
    <tbody>
    {{#if view.parentView.controller.isDatasetLoadingError}}
      <td class="first"></td>
      <td colspan="4">
        {{t mirroring.dataset.dataset.loading.instances}}
      </td>
    {{else}}
      {{#if view.isLoaded}}
        {{#if view.pageContent}}
          {{#each job in view.pageContent}}
            {{#view view.JobView contentBinding="job"}}
            <td class="first">
              <span {{ bindAttr class="job.healthClass"}}></span>
            </td>

            <td>{{unbound job.name}}</td>
            <td>{{unbound job.startFormatted}}</td>
            <td>{{unbound job.endFormatted}}</td>
            <td>
              {{#if view.showActions}}
                <div class="btn-group display-inline-block">
                  <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                    {{job.statusFormatted}}
                    <span class="caret"></span>
                  </a>
                  <ul class="dropdown-menu">
                    {{#if job.isSuspended}}
                      <li>
                        <a href="javascript:void(null)" {{action resumeInstance job target="controller"}}>{{t mirroring.dataset.resumeInstance}}</a>
                      </li>
                    {{else}}
                      <li>
                        <a href="javascript:void(null)" {{action suspendInstance job target="controller"}}>{{t mirroring.dataset.suspendInstance}}</a>
                      </li>
                    {{/if}}
                    <li>
                      <a href="javascript:void(null)" {{action killInstance job target="controller"}}>{{t mirroring.dataset.killInstance}}</a>
                    </li>
                  </ul>
                </div>
              {{else}}
                {{job.statusFormatted}}
              {{/if}}
            </td>
            {{/view}}
          {{/each}}
        {{else}}
          <tr>
            <td class="first"></td>
            <td colspan="4">
              {{t mirroring.table.noJobs}}
            </td>
          </tr>
        {{/if}}
      {{else}}
        <tr>
          <td class="first"></td>
          <td colspan="4">
            <div class="spinner"></div>
          </td>
        </tr>
      {{/if}}
    {{/if}}
    </tbody>
  </table>
  {{#if view.isLoaded}}
    <div class="page-bar">
      <div class="items-on-page">
        <label>{{t common.show}}
          : {{view view.rowsPerPageSelectView selectionBinding="view.displayLength"}}</label>
      </div>
      <div class="info">{{view.paginationInfo}}</div>
      <div class="paging_two_button">
        {{view view.paginationLeft}}
        {{view view.paginationRight}}
      </div>
    </div>
  {{/if}}
</div>
